﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Web.UI;

namespace Royaumes_Libres.Database
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks>Patrick Chabot</remarks>
    public class cWorldsAdminSetting
    {
        protected int pInitMana;
        protected int pInitTimber;
        protected int pInitOre;
        protected int pInitFood;
        protected int pInitPopulation;
        protected int pInitDisciple;
        protected int pInitLumberjack;
        protected int pInitMiner;
        protected int pInitFarmer;
        protected int pInitWorker;
        protected decimal pRateDisciple;
        protected decimal pRateLumberjack;
        protected decimal pRateMiner;
        protected decimal pRateFarmer;
        protected decimal pRateWorker;

        public int InitMana { get { return this.pInitMana; } set { this.pInitMana = value; } }
        public int InitTimber { get { return this.pInitTimber; } set { this.pInitTimber = value; } }
        public int InitOre { get { return this.pInitOre; } set { this.pInitOre = value; } }
        public int InitFood { get { return this.pInitFood; } set { this.pInitFood = value; } }
        public int InitPopulation { get { return this.pInitPopulation; } set { this.pInitPopulation = value; } }
        public int InitDisciple { get { return this.pInitDisciple; } set { this.pInitDisciple = value; } }
        public int InitLumberjack { get { return this.pInitLumberjack; } set { this.pInitLumberjack = value; } }
        public int InitMiner { get { return this.pInitMiner; } set { this.pInitMiner = value; } }
        public int InitFarmer { get { return this.pInitFarmer; } set { this.pInitFarmer = value; } }
        public int InitWorker { get { return this.pInitWorker; } set { this.pInitWorker = value; } }
        public decimal RateDisciple { get { return this.pRateDisciple; } set { this.pRateDisciple = value; } }
        public decimal RateLumberjack { get { return this.pRateLumberjack; } set { this.pRateLumberjack = value; } }
        public decimal RateMiner { get { return this.pRateMiner; } set { this.pRateMiner = value; } }
        public decimal RateFarmer { get { return this.pRateFarmer; } set { this.pRateFarmer = value; } }
        public decimal RateWorker { get { return this.pRateWorker; } set { this.pRateWorker = value; } }

        protected cWorldsAdminSetting() { }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        /// <remarks>Patrick Chabot</remarks>
        public static cWorldsAdminSetting GetWorldBase()
        {
            cWorldsAdminSetting world = new cWorldsAdminSetting();
            SqlCommand cmd = cSQL.GetDbJeuCommand();

            cmd.Connection.Open();
            cmd.CommandText = "[cde].[spGetWorldBase]";
            SqlDataReader dr = cmd.ExecuteReader();
            dr.Read();

            world.pInitMana = dr.GetInt32(0);
            world.pInitTimber = dr.GetInt32(1);
            world.pInitOre = dr.GetInt32(2);
            world.pInitFood = dr.GetInt32(3);
            world.pInitPopulation = dr.GetInt32(4);
            world.pInitDisciple = dr.GetInt32(5);
            world.pInitLumberjack = dr.GetInt32(6);
            world.pInitMiner = dr.GetInt32(7);
            world.pInitFarmer = dr.GetInt32(8);
            world.pInitWorker = dr.GetInt32(9);
            world.pRateDisciple = dr.GetDecimal(10);
            world.pRateLumberjack = dr.GetDecimal(11);
            world.pRateMiner = dr.GetDecimal(12);
            world.pRateFarmer = dr.GetDecimal(13);
            world.pRateWorker = dr.GetDecimal(14);

            cmd.Connection.Close();
            return world;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        /// <remarks>Patrick Chabot</remarks>
        public ucWorldBase GetControl(Page page)
        {
            ucWorldBase uc = (ucWorldBase)page.LoadControl("ucWorldBase.ascx");
            uc.WorldBase = this;
            return uc;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <remarks>Patrick Chabot</remarks>
        public void Save()
        {
            SqlCommand cmd = cSQL.GetDbJeuCommand();

            cmd.Connection.Open();
            cmd.CommandText = "[cde].[spSetWorldBase]";
            cmd.Parameters.Add(cSQL.Param("@InitMana", this.pInitMana, SqlDbType.Int));
            cmd.Parameters.Add(cSQL.Param("@InitTimber", this.pInitTimber, SqlDbType.Int));
            cmd.Parameters.Add(cSQL.Param("@InitOre", this.pInitOre, SqlDbType.Int));
            cmd.Parameters.Add(cSQL.Param("@InitFood", this.pInitFood, SqlDbType.Int));
            cmd.Parameters.Add(cSQL.Param("@InitPopulation", this.pInitPopulation, SqlDbType.Int));

            cmd.Parameters.Add(cSQL.Param("@InitDisciple", this.pInitDisciple, SqlDbType.Int));
            cmd.Parameters.Add(cSQL.Param("@InitLumberjack", this.pInitLumberjack, SqlDbType.Int));
            cmd.Parameters.Add(cSQL.Param("@InitMiner", this.pInitMiner, SqlDbType.Int));
            cmd.Parameters.Add(cSQL.Param("@InitFarmer", this.pInitFarmer, SqlDbType.Int));
            cmd.Parameters.Add(cSQL.Param("@InitWorker", this.pInitWorker, SqlDbType.Int));

            cmd.Parameters.Add(cSQL.Param("@RateDisciple", this.pRateDisciple, SqlDbType.Decimal));
            cmd.Parameters.Add(cSQL.Param("@RateLumberjack", this.pRateLumberjack, SqlDbType.Decimal));
            cmd.Parameters.Add(cSQL.Param("@RateMiner", this.pRateMiner, SqlDbType.Decimal));
            cmd.Parameters.Add(cSQL.Param("@RateFarmer", this.pRateFarmer, SqlDbType.Decimal));
            cmd.Parameters.Add(cSQL.Param("@RateWorker", this.pRateWorker, SqlDbType.Decimal));

            cmd.ExecuteNonQuery();
            cmd.Connection.Close();
        }
    }
}